﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace NFox.Pyeditor.Runtime
{
    public class BreakPointList : IEnumerable<BreakPoint>
    {

        private List<BreakPoint> _lst = new List<BreakPoint>();

        public bool Contains(BreakPoint pt)
        {
            foreach(var p in _lst)
            {
                if (p.Equals(pt))
                    return true;
            }
            return false;
        }

        public void Add(BreakPoint pt)
        {
            if(!Contains(pt))
                _lst.Add(pt);
        }

        public void AddRange(BreakPointList pts)
        {
            foreach (var pt in pts)
                Add(pt);
        }

        public void Add(string filename, int line)
        {
            Add(new BreakPoint(filename, line));
        }

        public void Remove(string filename, int line)
        {
            Remove(new BreakPoint(filename, line));
        }

        public void Remove(BreakPoint pt)
        {
            if (Contains(pt)) _lst.Remove(pt);
        }

        public void Remove(Func<BreakPoint, bool> func)
        {
            for(int i = _lst.Count - 1; i >= 0; i--)
            {
                if (func(_lst[i]))
                    _lst.RemoveAt(i);
            }
        }

        public void Clear()
        {
            _lst.Clear();
        }

        public IEnumerator<BreakPoint> GetEnumerator()
        {
            return _lst.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _lst.GetEnumerator();
        }
    }
}
